const parameter = getApp().globalData.parameter
const domainName = getApp().globalData.domainName

// pages/sysConfig/config_gs/add_gs_stem_type/add_gs_stem_type.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  input_name(e){
    this.setData({
      name:e.detail.value
    })
  },

  chooseimg(){
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      sizeType: ['compressed'],
      sourceType: ['album'],
      success: res => {
        let tempFile = res.tempFiles[0]
        if(tempFile.size>100000){
          wx.showModal({
            content: '该图片不能大于100KB',
            showCancel: false,
            title: '提示',
          })
          return
        }else{
          this.setData({
            tempFilePath :tempFile.tempFilePath
          })
        }
      },
    })
  },

  submit(){
    wx.showModal({
      content:'确定提交吗？',
      showCancel: true,
      title: '提示',
      success: res => {
        if(res.confirm){
          wx.uploadFile({
            filePath: this.data.tempFilePath,
            name: 'files',
            url: domainName + '/gs_stem_type_submit',
            formData: {
              name:this.data.name,
            },
            header : {'content-type':'application/x-www-form-urlencoded'},
            success: res => {
              if(JSON.parse(res.data).row_id){
                wx.showToast({
                  title: '添加完成！',
                })
                setTimeout(() => {
                  wx.navigateBack()
                }, 1500);
              }
            },
          })
        }
      },
    })
  },


})